home *** CD-ROM | disk | FTP | other *** search
- function doai()
- {
- if(players[1].state == 0)
- {
- bn = nearestball();
- if(bn >= 0)
- {
- if(cpulevel < math.random() * 50)
- {
- ctb = eval("ball" + bn);
- if(ctb._x < pl1._x - players[1].speed)
- {
- if(pl1.legs._currentframe == 1)
- {
- pl1.legs.gotoAndPlay("walk");
- }
- pl1._x -= players[1].speed;
- if(pl1._x < players[1].mx + pl1._width / 2)
- {
- pl1._x = players[1].mx + pl1._width / 2;
- }
- }
- else if(pl1._x + players[1].speed < ctb._x)
- {
- if(pl1.legs._currentframe == 1)
- {
- pl1.legs.gotoAndPlay("walk");
- }
- pl1._x += players[1].speed;
- if(players[1].my - pl1._width / 2 < pl1._x)
- {
- pl1._x = players[1].my - pl1._width / 2;
- }
- }
- }
- }
- else if(0 < players[1].ballsready.length)
- {
- if(pl1._x < 350)
- {
- if(pl1.legs._currentframe == 1)
- {
- pl1.legs.gotoAndPlay("walk");
- }
- pl1._x += players[1].speed;
- if(players[1].my - pl1._width / 2 < pl1._x)
- {
- pl1._x = players[1].my - pl1._width / 2;
- }
- }
- else
- {
- players[1].ballsloaded.push(players[1].ballsready.pop());
- players[1].ballload = players[1].loadspeed;
- players[1].state = 1;
- players[1].cpuangle = 90 - Math.atan(pl1._y / (pl1._x - 300)) * 57.29577951308232 + (Math.random() * cpulevel - cpulevel / 2);
- }
- }
- else if(pl1._x < balllying())
- {
- if(pl1.legs._currentframe == 1)
- {
- pl1.legs.gotoAndPlay("walk");
- }
- pl1._x += players[1].speed;
- if(players[1].my - pl1._width / 2 < pl1._x)
- {
- pl1._x = players[1].my - pl1._width / 2;
- }
- }
- else if(balllying() < pl1._x)
- {
- if(pl1.legs._currentframe == 1)
- {
- pl1.legs.gotoAndPlay("walk");
- }
- pl1._x -= players[1].speed;
- if(pl1._x < players[1].mx + pl1._width / 2)
- {
- pl1._x = players[1].mx + pl1._width / 2;
- }
- }
- }
- else if(players[1].state == 1)
- {
- if(0 < players[1].ballsready.length && 1 < Math.random() * 10)
- {
- players[1].ballload--;
- if(players[1].ballload == 0)
- {
- if(0 < players[1].ballsready.length)
- {
- players[1].ballsloaded.push(players[1].ballsready.pop());
- players[1].ballload = players[1].loadspeed;
- }
- }
- }
- else
- {
- players[1].state = 2;
- }
- }
- else if(players[1].state == 2)
- {
- players[1].ballload = 0;
- if(pl1.body._rotation >= players[1].cpuangle - 3 && players[1].cpuangle + 3 >= pl1.body._rotation)
- {
- players[1].state = 3;
- }
- else if(0 >= pl1.body._rotation)
- {
- pl1.body._rotation = 0;
- players[1].state = 3;
- }
- else
- {
- pl1.body._rotation -= 5;
- }
- }
- else if(players[1].state == 3)
- {
- if(players[1].ballload == 0)
- {
- if(0 < players[1].ballsloaded.length)
- {
- fireBall.start();
- tb = players[1].ballsloaded.pop();
- ty = players[1].scale * (0 + 52 * Math.sin((pl1.body._rotation - 88) * 0.017453292519943295));
- tx = players[1].scale * (- 52 * Math.cos((pl1.body._rotation - 88) * 0.017453292519943295));
- balls[tb].ystep = 0 + balls[tb].speed * Math.sin((pl1.body._rotation - 90) * 0.017453292519943295);
- balls[tb].xstep = - balls[tb].speed * Math.cos((pl1.body._rotation - 90) * 0.017453292519943295);
- tempb = eval("ball" + tb);
- tempb._x = pl1._x + tx;
- tempb._y = pl1._y + ty;
- if(275 >= tempb._x)
- {
- tempb._x = 279;
- balls[tb].xstep *= -1;
- }
- balls[tb].state = 1;
- balls[tb].hitby = ti;
- pl1.body._rotation -= 8;
- players[1].ballload = players[1].firespeed;
- }
- else
- {
- players[1].ballload = 0;
- players[1].state = 4;
- }
- }
- else
- {
- players[1].ballload--;
- }
- }
- else if(players[1].state == 4)
- {
- if(90 >= pl1.body._rotation)
- {
- pl1.body._rotation += 10;
- }
- else
- {
- pl1.body._rotation = 90;
- players[1].state = 0;
- }
- }
- }
- function nearestball()
- {
- lowest = 0;
- ballnum = -1;
- ci = 0;
- while(ci < ballsout)
- {
- if(balls[ci].state == 1)
- {
- cball = eval("ball" + ci);
- if(270 < cball._x && lowest < cball._y)
- {
- ballnum = ci;
- lowest = cball._y;
- }
- }
- ci++;
- }
- return ballnum;
- }
- function balllying()
- {
- lowest = 3000;
- ci = 0;
- while(ci < ballsout)
- {
- if(balls[ci].state == 20)
- {
- cball = eval("ball" + ci);
- tx = cball._x - pl1._x;
- if(Math.abs(tx) < Math.abs(lowest - pl1._x))
- {
- lowest = cball._x;
- }
- }
- ci++;
- }
- if(lowest == 3000)
- {
- return pl1._x;
- }
- return lowest;
- }
- ti = 0;
- while(ti < maxballs)
- {
- if(balls[ti].state == 1)
- {
- tball = eval("ball" + ti);
- balls[ti].ystep += balls[ti].gravity;
- if(90 < tball._y)
- {
- if(tball._x < 275 && tball._x + balls[ti].xstep >= 275)
- {
- tball._x = 271;
- balls[ti].xstep *= -1;
- }
- else if(275 < tball._x && 275 >= tball._x + balls[ti].xstep)
- {
- tball._x = 279;
- balls[ti].xstep *= -1;
- }
- }
- if(tball._x + balls[ti].xstep < 44)
- {
- tball._x = 44;
- balls[ti].xstep *= -1;
- }
- if(510 < tball._x + balls[ti].xstep)
- {
- tball._x = 510;
- balls[ti].xstep *= -1;
- }
- tball._x += balls[ti].xstep;
- tsy = tball._y;
- tball._y += balls[ti].ystep;
- if(pl0.body.funnel.hit.hitTest(tball._x,tball._y,true))
- {
- players[0].ballsready.push(ti);
- balls[ti].state = 0;
- tball._x = -20;
- }
- else if(pl1.body.funnel.hit.hitTest(tball._x,tball._y,true))
- {
- players[1].ballsready.push(ti);
- balls[ti].state = 0;
- tball._x = -20;
- }
- else if(tball._x < 275)
- {
- twall = eval("ground0" + (players[0].height - 1));
- if(twall._y < tball._y)
- {
- balls[ti].state = 10;
- tj = 0;
- while(tj < maxballs)
- {
- if(balls[tj].state == 10)
- {
- tjball = eval("ball" + tj);
- tjball._y = twall._y + twall._height - 9;
- }
- tj++;
- }
- twall.removeMovieClip();
- levelGo.start();
- players[0].height -= 1;
- dropcreature(0);
- if(players[0].height == 0)
- {
- gotoAndPlay(36);
- }
- }
- }
- else if(275 < tball._x)
- {
- twall = eval("ground1" + (players[1].height - 1));
- if(twall._y < tball._y)
- {
- balls[ti].state = 20;
- tj = 0;
- while(tj < maxballs)
- {
- if(balls[tj].state == 20)
- {
- tjball = eval("ball" + tj);
- tjball._y = twall._y + twall._height - 9;
- }
- tj++;
- }
- twall.removeMovieClip();
- levelGo.start();
- players[1].height -= 1;
- dropcreature(1);
- if(players[1].height == 0)
- {
- gotoAndPlay(33);
- }
- }
- c;
- }
- tk = 0;
- while(tk < tokensout)
- {
- ttok = eval("token" + tk);
- if(ttok.hitTest(tball._x,tball._y,true))
- {
- tokenPop.start();
- tokensout--;
- ttok._x = -100;
- if(ttok._currentframe == 2)
- {
- tbk = eval("ball" + ballsout);
- tbk._x = tball._x;
- tbk._y = tball._y;
- balls[ballsout].xstep = balls[ti].xstep * -1;
- balls[ballsout].ystep = balls[ti].ystep;
- balls[ballsout].state = 1;
- setballtype(ballsout,balls[ti].type);
- ballsout++;
- }
- else if(ttok._currentframe == 3)
- {
- if(balls[ti].type == 1)
- {
- balls[ti].xstep *= 0.4;
- balls[ti].ystep *= 0.4;
- }
- if(balls[ti].type == 3)
- {
- balls[ti].xstep *= 0.2;
- balls[ti].ystep *= 0.2;
- }
- setballtype(ti,2);
- }
- else if(ttok._currentframe == 4)
- {
- if(balls[ti].type == 2)
- {
- balls[ti].xstep *= 2;
- balls[ti].ystep *= 2;
- }
- if(balls[ti].type == 3)
- {
- balls[ti].xstep *= 0.5;
- balls[ti].ystep *= 0.5;
- }
- setballtype(ti,1);
- }
- else if(ttok._currentframe == 5)
- {
- if(balls[ti].type == 1)
- {
- balls[ti].xstep *= 1.5;
- balls[ti].ystep *= 1.5;
- }
- else if(balls[ti].type == 2)
- {
- balls[ti].xstep *= 2.6;
- balls[ti].ystep *= 2.6;
- }
- setballtype(ti,3);
- }
- else if(ttok._currentframe == 6)
- {
- if(1.4 >= players[balls[ti].hitby].scale)
- {
- players[balls[ti].hitby].scale += 0.2;
- tpl = eval("pl" + balls[ti].hitby);
- tpl._xscale = players[balls[ti].hitby].scale * 8;
- tpl._yscale = players[balls[ti].hitby].scale * 8;
- tpl._y -= 20;
- dropcreature(balls[ti].hitby);
- }
- }
- else if(ttok._currentframe == 7)
- {
- hb = (balls[ti].hitby + 1) % 2;
- if(players[hb].scale >= 1)
- {
- players[hb].scale -= 0.2;
- tpl = eval("pl" + hb);
- tpl._xscale = players[hb].scale * 8;
- tpl._yscale = players[hb].scale * 8;
- tpl._y -= 20;
- dropcreature(hb);
- }
- }
- }
- tk++;
- }
- if(0 < tsy && tball._y < 0)
- {
- tarrow.duplicateMovieClip("arrow" + ti,250 + ti);
- tar = eval("arrow" + ti);
- tar.gotoAndStop(balls[ti].type);
- }
- else if(tsy < 0 && 0 < tball._y)
- {
- tar = eval("arrow" + ti);
- tar.removeMovieClip();
- }
- tar = eval("arrow" + ti);
- if(tar != undefined)
- {
- tar._x = tball._x;
- tar._y = 0;
- }
- }
- else if(balls[ti].state == 10)
- {
- tball = eval("ball" + ti);
- if(tball._x < 48)
- {
- tball._x = 48;
- }
- if(263 < tball._x)
- {
- tball._x = 263;
- }
- if(pl0.hitTest(tball))
- {
- players[0].ballsready.push(ti);
- balls[ti].state = 0;
- tball._x = -20;
- }
- }
- else if(balls[ti].state == 20)
- {
- tball = eval("ball" + ti);
- if(500 < tball._x)
- {
- tball._x = 500;
- }
- if(tball._x < 298)
- {
- tball._x = 298;
- }
- if(pl1.hitTest(tball))
- {
- players[1].ballsready.push(ti);
- balls[ti].state = 0;
- tball._x = -20;
- }
- }
- ti++;
- }
- ti = 0;
- while(ti < humanplayers)
- {
- if(players[ti].state == 0)
- {
- if(Key.isDown(players[ti].leftk))
- {
- tempp = eval("pl" + ti);
- if(tempp.legs._currentframe == 1)
- {
- tempp.legs.gotoAndPlay("walk");
- }
- tempp._x -= players[ti].speed;
- if(tempp._x < players[ti].mx + tempp._width / 2)
- {
- tempp._x = players[ti].mx + tempp._width / 2;
- }
- }
- if(Key.isDown(players[ti].rightk))
- {
- tempp = eval("pl" + ti);
- if(tempp.legs._currentframe == 1)
- {
- tempp.legs.gotoAndPlay("walk");
- }
- tempp._x += players[ti].speed;
- if(players[ti].my - tempp._width / 2 < tempp._x)
- {
- tempp._x = players[ti].my - tempp._width / 2;
- }
- }
- if(Key.isDown(players[ti].firek))
- {
- if(0 < players[ti].ballsready.length)
- {
- players[ti].ballsloaded.push(players[ti].ballsready.pop());
- players[ti].ballload = players[ti].loadspeed;
- players[ti].state = 1;
- }
- }
- }
- else if(players[ti].state == 1)
- {
- if(Key.isDown(players[ti].firek))
- {
- players[ti].ballload--;
- if(players[ti].ballload == 0)
- {
- if(0 < players[ti].ballsready.length)
- {
- players[ti].ballsloaded.push(players[ti].ballsready.pop());
- players[ti].ballload = players[ti].loadspeed;
- }
- }
- }
- else
- {
- players[ti].state = 2;
- }
- }
- else if(players[ti].state == 2)
- {
- players[ti].ballload = 0;
- tempp = eval("pl" + ti);
- if(Key.isDown(players[ti].firek))
- {
- players[ti].state = 3;
- }
- else if(0 >= tempp.body._rotation)
- {
- tempp.body._rotation = 0;
- players[ti].state = 3;
- }
- else
- {
- tempp.body._rotation -= 5;
- }
- }
- else if(players[ti].state == 3)
- {
- if(players[ti].ballload == 0)
- {
- if(0 < players[ti].ballsloaded.length)
- {
- tb = players[ti].ballsloaded.pop();
- fireBall.start();
- tempp = eval("pl" + ti);
- if(ti == 0)
- {
- ty = players[ti].scale * (0 + 52 * Math.sin((tempp.body._rotation - 88) * 0.017453292519943295));
- tx = players[ti].scale * (0 + 52 * Math.cos((tempp.body._rotation - 88) * 0.017453292519943295));
- balls[tb].ystep = 0 + balls[tb].speed * Math.sin((tempp.body._rotation - 90) * 0.017453292519943295);
- balls[tb].xstep = 0 + balls[tb].speed * Math.cos((tempp.body._rotation - 90) * 0.017453292519943295);
- tempb = eval("ball" + tb);
- tempb._x = tempp._x + tx;
- tempb._y = tempp._y + ty;
- if(tempb._x >= 275)
- {
- tempb._x = 271;
- balls[tb].xstep *= -1;
- }
- }
- else
- {
- ty = players[ti].scale * (0 + 52 * Math.sin((tempp.body._rotation - 88) * 0.017453292519943295));
- tx = players[ti].scale * (- 52 * Math.cos((tempp.body._rotation - 88) * 0.017453292519943295));
- balls[tb].ystep = 0 + balls[tb].speed * Math.sin((tempp.body._rotation - 90) * 0.017453292519943295);
- balls[tb].xstep = - balls[tb].speed * Math.cos((tempp.body._rotation - 90) * 0.017453292519943295);
- tempb = eval("ball" + tb);
- tempb._x = tempp._x + tx;
- tempb._y = tempp._y + ty;
- if(275 >= tempb._x)
- {
- tempb._x = 279;
- balls[tb].xstep *= -1;
- }
- }
- balls[tb].state = 1;
- balls[tb].hitby = ti;
- tempp.body._rotation -= 8;
- players[ti].ballload = players[ti].firespeed;
- }
- else
- {
- players[ti].ballload = 0;
- players[ti].state = 4;
- }
- }
- else
- {
- players[ti].ballload--;
- }
- }
- else if(players[ti].state == 4)
- {
- tempp = eval("pl" + ti);
- if(90 >= tempp.body._rotation)
- {
- tempp.body._rotation += 10;
- }
- else
- {
- tempp.body._rotation = 90;
- players[ti].state = 0;
- }
- }
- ti++;
- }
- if(humanplayers < 2)
- {
- doai();
- }
- pl0.body.funnel.gotoAndStop(players[0].ballsready.length + 1);
- tbll = eval("pl0.body.funnel.ball" + (players[0].ballsready.length - 1));
- tbll.gotoAndStop(balls[players[0].ballsready[players[0].ballsready.length - 1]].type);
- pl1.body.funnel.gotoAndStop(players[1].ballsready.length + 1);
- tbll = eval("pl1.body.funnel.ball" + (players[1].ballsready.length - 1));
- tbll.gotoAndStop(balls[players[1].ballsready[players[1].ballsready.length - 1]].type);
- placetoken();
-